<g:setProvider library="jquery"/>

<x:pager/>
<table id="courseTable" class="tablesorter">
    <thead>
        <tr>
            <th/>
            <th>${message(code: 'course.name.label', default: 'Name')}</th>
            <th>${message(code: 'course.category.label', default: 'Category')}</th>
            <th>${message(code: 'course.grade.label', default: 'Grade')}</th>
            <th style="display:none">${message(code: 'course.capacity.label', default: 'Capacity')}</th>
            <th style="display:none">${message(code: 'course.regCapacity.label', default: 'Reg Cap.')}</th>
            <th>${message(code: 'course.price.label', default: 'Price')}</th>
            <th>${message(code: 'course.startTime.label', default: 'Start Time')}</th>
            <th>${message(code: 'course.endTime.label', default: 'End Time')}</th>
            <th>${message(code: 'course.teacher.label', default: 'Teacher')}</th>
            <th>${message(code: 'course.book.label', default: 'Book')}</th>
            <th>${message(code: 'course.roomNo.label', default: 'Room')}</th>
            <th>${message(code: 'course.semester.label', default: 'semester')}</th>
            <th style="display:none">${message(code: 'course.status.label', default: 'Status')}</th>
            <g:if test="${session.roles?.contains('ROLE_ADMIN')}">
              <th class="delete">Del</th>
              <th class="edit">Edit</th>
            </g:if>

        </tr>
    </thead>
    <tbody>
    <g:each in="${instanceList}" status="i" var="courseInstance">
        <tr>
            <td>${i+1}</td>
            <td class="show"><a href="#" title="Course Detail" rel="${request.contextPath}/course/show/${courseInstance.id}">${fieldValue(bean: courseInstance, field: "name")}</a></td>
            <td>${fieldValue(bean: courseInstance, field: "category")}</td>
            <td>${fieldValue(bean: courseInstance, field: "grade")}</td>
            <td style="display:none">${fieldValue(bean: courseInstance, field: "capacity")}</td>
            <td style="display:none">${fieldValue(bean: courseInstance, field: "regCapacity")}</td>
            <td>${fieldValue(bean: courseInstance, field: "price")}</td>
            <td>${fieldValue(bean: courseInstance, field: "startTime")}</td>
            <td>${fieldValue(bean: courseInstance, field: "endTime")}</td>
            <td>${fieldValue(bean: courseInstance, field: "teacher")}</td>
            <td class="show"><a href="#" title="Book Detail" rel="${request.contextPath}/book/show/${courseInstance.book?.id}">${fieldValue(bean: courseInstance, field: "book")}</a></td>
            <td>${fieldValue(bean: courseInstance, field: "classRoom")}</td>
            <td>${fieldValue(bean: courseInstance, field: "semester")}</td>
            <td style="display:none">${fieldValue(bean: courseInstance, field: "status")}</td>
            <g:if test="${session.roles?.contains('ROLE_ADMIN')}">
              <td class="delete"><g:remoteLink action="delete" update="content" before="if(!confirm('Are you sure?')) return false;" id="${courseInstance.id}"><span class="ui-icon ui-icon-trash"/></g:remoteLink></td>
              <td class="edit"><a href="#" title="Edit Course" rel="${request.contextPath}/course/create/${courseInstance.id}"><span class="ui-icon ui-icon-pencil"/></a></td>
            </g:if>
        </tr>
    </g:each>
    </tbody>
</table>
<script type="text/javascript">
  setupAdminList({controller:'course', action:'list'});
</script>
